package twobranchTree.haspathsum;

import twobranchTree.preorderTraversal.TreeNode;

/**
 * @Date 2020/2/23
 * @author 王光浩 
 * @Thinking 使用前序递归方法进行
 */
public class MyMethodOne {
	private boolean judge=false;
	private int sum;
	public boolean hasPathSum(TreeNode root, int sum) {
		if(root==null)return false; //节点为空
		else if(root.left==null && root.right==null) {
			if(sum-root.val==0)
				return true;
			return false;
		}
		else return hasPathSum(root.left,sum-root.val) || hasPathSum(root.right,sum-root.val);
	}
}
